﻿using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Xml;

namespace Universe.WCF.Behaviors.Test
{
    class MyEnvionment
    {
        public static ServiceHost CreateService<Contract, Service>()
        {
            ServiceHost sh = new ServiceHost(typeof(Service));
            NetNamedPipeBinding pipe = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            pipe.ReaderQuotas = XmlDictionaryReaderQuotas.Max;
            pipe.MaxReceivedMessageSize = Int32.MaxValue;
            string uri = string.Format("net.pipe://localhost/my/{0}", typeof(Contract).Name);
            EndpointAddress endpoint = new EndpointAddress(uri);
            ServiceEndpoint ep = sh.AddServiceEndpoint(typeof(Contract), pipe, endpoint.Uri);
            return sh;
        }

        public static ChannelFactory<Contract> CreateProxy<Contract>()
        {
            NetNamedPipeBinding pipe = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            pipe.ReaderQuotas = XmlDictionaryReaderQuotas.Max;
            pipe.MaxReceivedMessageSize = Int32.MaxValue;
            ChannelFactory<Contract> cf = new ChannelFactory<Contract>(pipe);
            return cf;

        }

        public static string GetContractUri<Contract>()
        {
            return string.Format("net.pipe://localhost/my/{0}", typeof(Contract).Name);
        }

        public static EndpointAddress GetEndPointUri<Contract>()
        {
            return
                new EndpointAddress(
                    string.Format("net.pipe://localhost/my/{0}", typeof (Contract).Name)
                    );
        }
    }
}
